package com.zznode.redsun.commons.dto;

import org.springframework.util.StringUtils;

import com.zznode.csp.domain.commons.util.MapCreaterBuilder;

public class CustomerQuery extends QueryParameter {
	private String monthlyIncomeId;
	private String hobbiesId;
	private String receiveDoc;
	private String professionId;
	private String levelId;
	private String typeId;
	private String phone;

	@Override
	public String buildSql(String querySql, MapCreaterBuilder parameters) {
		StringBuilder builder = new StringBuilder(super.buildSql(querySql, parameters, "b_customer."));
		if (StringUtils.hasText(monthlyIncomeId)) {
			builder.append(" and b_customer.monthly_income = :monthlyIncomeId");
			parameters.put("monthlyIncomeId", monthlyIncomeId);
		}
		if (StringUtils.hasText(hobbiesId)) {
			builder.append(" and b_customer_hobby.hobby_id = :hobbiesId");
			parameters.put("hobbiesId", hobbiesId);
		}
		if (StringUtils.hasText(receiveDoc)) {
			builder.append(" and b_customer.receive_doc = :receiveDoc");
			parameters.put("receiveDoc", Boolean.valueOf(receiveDoc));
		}
		if (StringUtils.hasText(professionId)) {
			builder.append(" and b_customer.profession_id = :professionId");
			parameters.put("professionId", professionId);
		}
		if (StringUtils.hasText(levelId)) {
			builder.append(" and b_customer.level_id = :levelId");
			parameters.put("levelId", levelId);
		}
		if (StringUtils.hasText(typeId)) {
			builder.append(" and b_customer.type_id = :typeId");
			parameters.put("typeId", typeId);
		}
		if (StringUtils.hasText(phone)) {
			builder.append(" and (b_personal_info.phone1 like :phone or b_personal_info.phone2 like :phone)");
			parameters.put("phone", "%" + phone + "%");
		}
		return builder.toString();
	}

	public String getMonthlyIncomeId() {
		return monthlyIncomeId;
	}

	public void setMonthlyIncomeId(String monthlyIncomeId) {
		this.monthlyIncomeId = monthlyIncomeId;
	}

	public String getHobbiesId() {
		return hobbiesId;
	}

	public void setHobbiesId(String hobbiesId) {
		this.hobbiesId = hobbiesId;
	}

	public String getReceiveDoc() {
		return receiveDoc;
	}

	public void setReceiveDoc(String receiveDoc) {
		this.receiveDoc = receiveDoc;
	}

	public String getProfessionId() {
		return professionId;
	}

	public void setProfessionId(String professionId) {
		this.professionId = professionId;
	}

	public String getLevelId() {
		return levelId;
	}

	public void setLevelId(String levelId) {
		this.levelId = levelId;
	}

	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

}
